namespace CSharpPro._0930;

public class Demo
{
    public void TestPrint1()
    {
        Console.WriteLine("请输入三个整数 x、y、z：");
        int x = int.Parse(Console.ReadLine());
        int y = int.Parse(Console.ReadLine());
        int z = int.Parse(Console.ReadLine());
        int temp;
        if (x > y)
        {
            temp = x;
            x = y;
            y = temp;
        }
        if (x > z)
        {
            temp = x;
            x = z;
            z = temp;
        }   
        if (y > z)
        {
            temp = y;
            y = z;
            z = temp;
        }
        Console.WriteLine($"从小到大排序为：{x} {y} {z}");
    }

    public void TestPrint2()
    {
        int sum = 0;
        for (int i = 1; i <= 100; i++)
        {
            if (i % 7 != 0 && !i.ToString().Contains("7"))
            {
                Console.Write(i + " ");
                sum += i;
            }
        }
        Console.WriteLine($"\n这些数字的和为：{sum}");
    }

    public void TestPrint3()
    {
        for (int i = 1; i <= 9; i++)
        {
            for (int j = 1; j <= i; j++)
            {
                Console.Write($"{j}×{i}={i * j}\t");
            }
            Console.WriteLine();
        }
    }

    public void TestPrint4()
    {
        List<int> perfectNumbers = new List<int>();
        for (int i = 1; i < 1000; i++)
        {
            int sum = 0;
            for (int j = 1; j < i; j++)
            {
                if (i % j == 0)
                {
                    sum += j;
                }
            }
            if (sum == i)
            {
                perfectNumbers.Add(i);
            }
        }
        Console.WriteLine("1000 以内的完数有：");
        foreach (int num in perfectNumbers)
        {
            Console.Write(num + " ");
        }
        Console.WriteLine();
    
    }

    public void TestPrint5()
    {
        Console.WriteLine("请输入一个正整数：");
        int num = int.Parse(Console.ReadLine());
        int temp = num;
        int digitCount = 0;
        while (temp > 0)
        {
            temp /= 10;
            digitCount++;
        }
        Console.WriteLine($"它是 {digitCount} 位数");
        Console.Write("逆序各位数字为：");
        temp = num;
        while (temp > 0)
        {
            int digit = temp % 10;
            Console.Write(digit);
            temp /= 10;
        }
        Console.WriteLine();
    }

    public void TestPrint6()
    {
        Console.WriteLine("请输入菱形的行数（奇数）：");
        int n = int.Parse(Console.ReadLine());
        int half = n / 2;
        for (int i = 0; i <= half; i++)
        {
            for (int j = 0; j < half - i; j++)
            {
                Console.Write(" ");
            }
            for (int j = 0; j < 2 * i + 1; j++)
            {
                Console.Write("*");
            }
            Console.WriteLine();
        }
        for (int i = half - 1; i >= 0; i--)
        {
            for (int j = 0; j < half - i; j++)
            {
                Console.Write(" ");
            }
            for (int j = 0; j < 2 * i + 1; j++)
            {
                Console.Write("*");
            }
            Console.WriteLine();
        }
    }
}